using System;
using System.Collections.Generic;
using System.Text;

namespace Instedd.Labs.Geo.Library
{
    delegate T FactoryMethod<T>();

    internal static class FactoryUtil
    {
        public static T CreateIfItIsNull<T>(ref T instance) where T : new()
        {
            return CreateIfItIsNull<T>(ref instance, delegate() { return new T(); });
        }

        public static T CreateIfItIsNull<T>(ref T instance, FactoryMethod<T> factoryMethod)
        {
            if (instance == null)
            {
                instance = factoryMethod();
            }

            return instance;
        }
    }
}